package com.vitabuybuy.tv.ui.mine.group

import android.os.Bundle
import com.flyco.tablayout.listener.CustomTabEntity
import com.flyco.tablayout.listener.OnTabSelectListener
import com.library.common.base.BaseActivity
import com.library.common.util.FragmentUtils
import com.vitabuybuy.tv.R
import com.vitabuybuy.tv.databinding.ActivityMyBiddingBinding
import com.vitabuybuy.tv.dto.TabEntity
import com.vitabuybuy.tv.ui.mine.group.viewmodel.MyGroupVieModel
import kotlinx.android.synthetic.main.activity_my_group_buy.*

class MyGroupBuyActivity : BaseActivity<MyGroupVieModel, ActivityMyBiddingBinding>() {

    override val isUseBaseTitleBar: Boolean
        get() = true
    override val layoutId: Int
        get() = R.layout.activity_my_group_buy

    private val mTabEntities = ArrayList<CustomTabEntity>()

    override fun initView(savedInstanceState: Bundle?) {
        setTitle(getString(R.string.my_group_buy))
        mTabEntities.add(TabEntity(getString(R.string.normal_group_buy), 0, 0))
        mTabEntities.add(TabEntity(getString(R.string.limited_group_buy), 0, 0))
        mTabLayout_1.setTabData(mTabEntities)
        replaceFragment(0)
    }

    override fun eventHandling() {
        mTabLayout_1.setOnTabSelectListener(object : OnTabSelectListener {
            override fun onTabSelect(position: Int) {
                replaceFragment(position)
            }
            override fun onTabReselect(position: Int) {
            }
        })
    }

    private fun replaceFragment(index: Int) {
        var tag = ""
        tag = when (index) {
            0 -> ClusterFragment::class.java.name
            1 -> LimitedFragment::class.java.name
            else -> ""
        }
        FragmentUtils.replaceFragment(supportFragmentManager, R.id.containerFragment, tag)
    }

    companion object {
        fun openActivity(mContext: BaseActivity<*, *>) {
            mContext.startActivity(null, MyGroupBuyActivity::class.java)
        }
    }
}
